package main

import "github.com/gin-gonic/gin"

type UserInfo struct {
	Username string `form:"username"` //反射查找
	Password string `form:"password"`
}

func main() {
	r := gin.Default()
	r.GET("/", func(ctx *gin.Context) {

		var u UserInfo
		err := ctx.ShouldBind(&u) //传输值
		if err != nil {
			ctx.JSON(200, gin.H{
				"error": err.Error(),
			})
		} else {
			ctx.JSON(200, gin.H{
				"200": "ok",
			})
		}
	})
	r.POST("/user", func(c *gin.Context) {
		sername := c.Param("username")
		assword := c.Param("password")

		c.JSON(200, gin.H{
			"username": sername,
			"password": assword,
		})
	})
	r.Run(":8080")
}
